<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
		<% 
String path = request.getContextPath(); 
// 获得项目完全路径（假设你的项目叫MyApp，那么获得到的地址就是 http://localhost:8080/MyApp/）: 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE html>
<html>
<head>
<base href=" <%=basePath%>"> 
<meta name="description" content="会员管理">
<meta name="author" content="xwj">
<title>会员管理管理</title>
<link href="bootstrap/bootstrap.css" rel="stylesheet">

<link href="css/admin_css/assets/font-awesome/css/font-awesome.css"
	rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/css/zabuto_calendar.css">
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/js/gritter/css/jquery.gritter.css" />
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/lineicons/style.css">

<link href="css/admin_css/assets/css/style.css" rel="stylesheet">
<link href="css/admin_css/assets/css/style-responsive.css"
	rel="stylesheet">
<script src="jquery/jquery-2.2.4.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>

<script class="include" type="text/javascript"
	src="css/admin_css/assets/js/jquery.dcjqaccordion.2.7.js"></script>
<script src="css/admin_css/assets/js/jquery.scrollTo.min.js"></script>
<script src="css/admin_css/assets/js/common-scripts.js"></script>

<script src="bootstrap/bootstrap.min.js"></script>
<!-- 表单验证 -->
<script
	src="bootstrap/bootstrapvalidator/js/bootstrapValidator.min.js"></script>

<script>
	var pageNum = 1;

	$(function() {
		getMember();
		
	});

	//分页查询
	function getMember() {
		$.ajax({
					url : "memberMsg/getAllMember.do", // 请求地址
					type : "POST", // 请求类型
					async : "true", // 是否异步方式
					data : {},
					dataType : "json", // 返回数据格式
					success : function(data) {
						var tbodys = $("tbody").empty();
						if (data.res == 1) {
							totalPage=data.totalPage;
							$.each(data.list,function(index, element) {
								if(element.mid<99){
								var trs="<tr><td>"
									+ (index + 1)
									+ "<input type='hidden' value='"+element.mid+"'></td>"
									+ "<td>"
									+ element.mname
									+ "</td>"
									+ "<td>"
									+ element.mdiscount
									+ "</td>"
									+ "<td>"
									+ element.mintegral
									+ "</td><td>"
									+ "<button  onclick='editInfo(this)' class='btn btn-primary btn-xs'>"
									+ "<i class='fa fa-pencil'></i></button>"
									+"</td></tr>";		
									tbodys.append(trs);
									}else if(element.mid==100){
										var money=element.mdiscount;
										$("input[name='up_money']").val(money);
									}
									});
						}

					}
				});

	}

	
	//修改会员名称
	function update() {
		var mname=$("input[name='mname']").val();
		var mid=$("input[name='mid']").val();
		
		if (!confirm("确认要修改吗?")) {
			return;
		}
		$.ajax({
			url : 'memberMsg/updateName.do',
			type : 'POST',
			async : "true",
			data : {
				"mid":mid,
				"mname":mname
			},
			dataType : 'json',
			success : function(data) {
				if (data.res == 1) {
					alert("修改成功");
					getMember();
				}
			}
		});
	}
	//修改会员积分所需消费
	function updateMoney() {
		var money=$("input[name='up_money']").val();
		
		if (!confirm("确认要修改吗?")) {
			return;
		}
		$.ajax({
			url : 'memberMsg/updateMoney.do',
			type : 'POST',
			async : "true",
			data : {
				"money":money
			},
			dataType : 'json',
			success : function(data) {
				if (data.res == 1) {
					alert("修改成功");
					getMember();
				}
			}
		});
	}
	//向编辑模态框传递信息
	function editInfo(obj) {
		var tds = $(obj).parent().parent().find('td');
		var cid = tds.eq(0).find('input').eq(0);
		$('#up_mid').val(cid.val());
		$('#up_mname').val(tds.eq(1).text());
		$('#up_mdiscount').val(tds.eq(2).text());
		$('#up_mintegral').val(tds.eq(3).text());

		//修改模态框
		$('#updateModal').modal('show');
		/*  var sex = $('#sex').val(tds.eq(2).text());   
		    if (sex == '女') {    
		        document.getElementById('women').checked = true;    
		    } else {    
		        document.getElementById('man').checked = true;    
		    }     */
	}

</script>

</head>
<body>
	<section id="container">

		<!--header start-->
		<%@include file="header.jsp"%>
		<!--header end-->

		<!--sidebar start-->
		<aside>
			<div id="sidebar" class="nav-collapse ">
				<!-- sidebar menu start-->
				<ul class="sidebar-menu" id="nav-accordion">

					<p class="centered">
						<a href="admin/adminmag.jsp"><img
							src="images/admin7.png" class="img-circle"
							width="60"></a>
					</p>
					<h5 class="centered">${admin.aname}</h5>

					<li class="mt"><a href="admin/index.jsp"> <i
							class="fa fa-bar-chart-o"></i> <span>销售统计</span>
					</a></li>

					<li class="sub-menu"><a  href="javascript:;">
							<i class="fa fa-book"></i> <span>书籍</span>
					</a>
						<ul class="sub">
							<li><a href="admin/bookmag.jsp">书籍管理</a></li>
							<li ><a href="admin/categorymag.jsp">类别管理</a></li>

						</ul></li>

					<li class="sub-menu"><a href="javascript:;"> <i
							class="fa fa-users"></i> <span>账户</span>
					</a>
						<ul class="sub">
							<li><a href="admin/usermag.jsp">用户管理</a></li>
							<li><a href="admin/admin.jsp">管理员管理</a></li>

						</ul></li>
					<li class="sub-menu"><a class="active" href="javascript:;"> <i
							class="fa fa-user"></i> <span>会员</span>
					</a>
						<ul class="sub">
							<li class="active"><a href="admin/membermag.jsp">会员折扣管理</a></li>

						</ul></li>
					<li class="sub-menu"><a href="javascript:;"> <i
							class="fa fa-shopping-cart"></i> <span>订单</span>
					</a>
						<ul class="sub">
							<li><a href="admin/ordermag.jsp">订单管理</a></li>
						</ul></li>

				</ul>
				<!-- sidebar menu end-->
			</div>
		</aside>
		<!--sidebar end-->
		<!-- **********************************************************************************************************************************************************
     以上是不变的内容--包括上边header和左边aside33###以下是变化的内容
      *********************************************************************************************************************************************************** -->

		<!--main content start-->
		<section id="main-content">
			<section class="wrapper">
				<h3>
					<i class="fa fa-angle-right"></i> 会员折扣管理
				</h3>
				<div class="row mt">
					<div class="col-lg-12">
						<div class="form-panel">
							<h5 class="mb">
								<i class="fa fa-bullhorn"></i>#--1积分所需消费--#
							</h5>
							<form class="form-inline" role="form" id="selform">
							<div class="form-group">
							<label class="control-label"></label>
								<input type="number" name="up_money" class="form-control col-sm-6" id="firstname"
										placeholder="请输入所需消费">
							<label class="control-label">元</label>
								<button type="button" class="btn btn-theme"
									onclick="updateMoney()">修改</button>
								</div>
							</form>

						</div>
					</div>
				</div>
				<div class="row mt">
					<div class="col-md-12">
						<div class="content-panel">
							<table class="table table-striped table-advance table-hover">
								<!--   	  <h4><i class="fa fa-angle-right"></i> 书籍信息</h4>  -->
								<thead>
									<tr>
										<th><i class="fa fa-bullhorn"></i> #</th>
										<th><i class="fa fa-bullhorn"></i> 会员名称</th>
										<th><i class="fa fa-bullhorn"></i> 折扣</th>
										<th><i class="fa fa-bullhorn"></i> 所需积分</th>
										<th>管理</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>

						</div>

					</div>
				</div>
				
			</section>
		</section>
		<!-- /MAIN CONTENT -->

		<!--main content end-->
		<!--footer start-->
		<%@include file="footer.jsp"%>
		<!--footer end-->
	</section>

	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="updateModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">会员折扣信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" role="form" id="up_form">
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="mid" id="up_mid"
									readonly placeholder="会员折扣ID" /> 
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">会员名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="up_mname"
									name="mname" placeholder="请输入会员">
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">会员折扣</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="up_mdiscount"
								readonly	name="mdiscount" placeholder="请输入会员">
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">所需积分</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="up_mintegral"
									readonly name="mintegral" placeholder="请输入会员">
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<button type="button" class="btn btn-primary" data-dismiss="modal"
						id="up_btn" onclick="update()">修改</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>


</body>
</html>